<?php
/**
 * @var $this Pinenut\Action
 * @var $companionProfileId string
 * @var $myProfileId string
 * @var $companionProfile \Users\Profile
 */


if ( ! method_exists($companionProfile, 'getAvatar')) {
    return;
}

$avatarTypeClass = $companionProfile->getAvatarType();
if (null !== $avatarTypeClass) {
	$avatarTypeClass .= '-profile';
}

/** @var \Messenger\Groups $groupModel */
$groupId = \Messenger\Groups::getList([$myProfileId, $companionProfileId], 1)[0];
$isFavorite = $groupId->hasRelation($myProfileId, \Messenger\Relations::STATUS_FAVORITE);

$aboutMe = mb_substr($companionProfile->aboutMe, 0, 128, 'utf8');
if (mb_strlen($companionProfile->aboutMe, 'utf8') > 128) {
    $aboutMe .= ' ...';
}
$companionUrl = $this->url('profiles.main', ['id' => $companionProfile->_id]);
$cityWithCountry = $this->action('geo.cityWithCountry',['id'=>(string)$companionProfile->homeCity]);
?>
    <div class="md-header">
        <div class="md-main-info">
			<a class="md-mi-avatar-wrapper <?php echo $avatarTypeClass ?>" href="<?= $companionUrl ?>">

				<div class="md-mi-avatar avatar-sm avatar-item"
				<?php if (null === $avatarTypeClass) { ?>
						 style="background-image: url(<?php
						 echo $this->url(
								 'photos.thumb', ['id' => $companionProfile->getAvatar()->_id, 'thumb' => 'messenger']
						 );
						 ?>)"
				<?php } ?>
				></div>

				<?php echo $this->action('profiles.online', ['id'=>(string)$companionProfile], 'messenger')?>

			</a>
            <a href="<?= $companionUrl ?>" class="md-mi-name">
                <?php echo $this->txt2html($companionProfile->nickname); ?>
                <span class="md-mi-country"><?php echo $cityWithCountry=='' ? '' : ", ".$cityWithCountry?></span>
            </a>
            <div class="md-mi-desire"><?php echo $this->txt2html($aboutMe); ?></div>
        </div>
        <div class="md-interests">
            <?php if (count($companionProfile->interests->getIds())) : ?>
                <?= $this->action('profiles.interests', [
                        'interests' => $companionProfile->interests->getIds(),
                        'limit' => 4,
                        'profileId' => (string)$companionProfile,
                    ]) ?>
            <?php endif; ?>
        </div>
        <div id="messenger-messages-area-favorite" targetProfileId="<?php echo $companionProfile; ?>" newRelationStatus="<?php echo $isFavorite ? \Messenger\Relations::STATUS_NEUTRAL : \Messenger\Relations::STATUS_FAVORITE; ?>" class="<?php echo $isFavorite ?  'md-favorite' : 'md-non-favorite'; ?>"></div>
    </div>

    <?php echo $this->action('.list', [
            'groupId' => (string)$groupId,
            'myProfileId' => $myProfileId,
            'companionProfileId' => $companionProfileId,
     ]); ?>

    <?php echo $this->action(
        '.send.area',
        [
            'groupId' => (string)$groupId,
            'myProfileId' => $myProfileId,
            'companionProfileId' => $companionProfileId,
        ]
    ); ?>
